package edu.unipd.p2t.communicaton;

import java.io.IOException;
import java.util.HashSet;

import edu.unipd.p2t.db.Message;

/**
 * This interface describes the method needed by the CommunicationManager to allow message exchange
 * @author Tommaso Dal Sasso
 *
 */
public interface p2tDevice {

	
	/**
	 * Sends an array containing the hashes of the messages to be sent
	 * @param hl the array containing hash
	 */
	public void sendHashList( HashSet<String> hl ) throws IOException;
	
	
	/**
	 * 
	 * @return
	 */
	public HashSet<String> receiveIdList() throws IOException;
	
	
	/**
	 * Sends a message to the remot\e device
	 * @param msgs an array containing the messages to be sent
	 */
	public void sendMessages( Message[] msgs ) throws IOException;
	
	
	/**
	 * Awaits for a message to be received from remote device
	 * @return an array containing the messages received
	 */
	public Message[] receiveMessages() throws IOException;
	
	
	/**
	 * Ends the current transmit session and closes the device communications
	 */
	public void close();
	
	
	/**
	 * Tells il the device is the one that has to start the communication
	 * @return true if the device is the first, false otherwise
	 */
	public boolean isFirst();
}
